package com.weijian.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weijian.bizmq.MyMessageProducer;
import com.weijian.common.pojo.CommonResult;
import com.weijian.dal.dataobject.ImageAI;
import com.weijian.dal.enums.ImageStatusEnum;
import com.weijian.dal.vo.ImageAIVO;
import com.weijian.mapper.ImageAIMapper;
import com.weijian.service.ImageAIService;
import com.weijian.manager.RedisLimiterManager;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class ImageServiceImpl extends ServiceImpl<ImageAIMapper, ImageAI> implements ImageAIService {

    final MyMessageProducer messageProducer;

    final RedisLimiterManager redisLimiterManager;

    @Override
    public CommonResult<ImageAIVO> imageChat(String message) {
        redisLimiterManager.doRateLimit("chat");
        ImageAI imageAI = new ImageAI();
        imageAI.setUserPrompt(message);
        imageAI.setStatus(ImageStatusEnum.ENQUEUE.getValue());
        save(imageAI);
        messageProducer.sendMessage(String.valueOf(imageAI.getId()));
        ImageAIVO imageAIVO = new ImageAIVO();
        return CommonResult.success(imageAIVO);
    }

    @Override
    public CommonResult<ImageAIVO> imageShow(Long id) {
        return CommonResult.success(new ImageAIVO());
    }
}
